/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_regionDAOImpl implements orm.dao.Tbv_regionDAO {
	public Tbv_region loadTbv_regionByORMID(int re_id_region) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_regionByORMID(session, re_id_region);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region getTbv_regionByORMID(int re_id_region) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_regionByORMID(session, re_id_region);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region loadTbv_regionByORMID(int re_id_region, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_regionByORMID(session, re_id_region, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region getTbv_regionByORMID(int re_id_region, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_regionByORMID(session, re_id_region, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region loadTbv_regionByORMID(PersistentSession session, int re_id_region) throws PersistentException {
		try {
			return (Tbv_region) session.load(orm.Tbv_region.class, new Integer(re_id_region));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region getTbv_regionByORMID(PersistentSession session, int re_id_region) throws PersistentException {
		try {
			return (Tbv_region) session.get(orm.Tbv_region.class, new Integer(re_id_region));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region loadTbv_regionByORMID(PersistentSession session, int re_id_region, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_region) session.load(orm.Tbv_region.class, new Integer(re_id_region), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region getTbv_regionByORMID(PersistentSession session, int re_id_region, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_region) session.get(orm.Tbv_region.class, new Integer(re_id_region), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region[] listTbv_regionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_regionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region[] listTbv_regionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_regionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region[] listTbv_regionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_region as Tbv_region");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_region[]) list.toArray(new Tbv_region[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region[] listTbv_regionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_region as Tbv_region");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_region[]) list.toArray(new Tbv_region[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region loadTbv_regionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_regionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region loadTbv_regionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_regionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region loadTbv_regionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_region[] tbv_regions = listTbv_regionByQuery(session, condition, orderBy);
		if (tbv_regions != null && tbv_regions.length > 0)
			return tbv_regions[0];
		else
			return null;
	}
	
	public Tbv_region loadTbv_regionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_region[] tbv_regions = listTbv_regionByQuery(session, condition, orderBy, lockMode);
		if (tbv_regions != null && tbv_regions.length > 0)
			return tbv_regions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_regionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_regionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_regionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_regionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_regionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_region as Tbv_region");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_regionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_region as Tbv_region");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region createTbv_region() {
		return new orm.Tbv_region();
	}
	
	public boolean save(orm.Tbv_region tbv_region) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_region);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_region tbv_region) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_region);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_region tbv_region)throws PersistentException {
		try {
			orm.Tbv_provincia[] lTbv_provincias = tbv_region.tbv_provincia.toArray();
			for(int i = 0; i < lTbv_provincias.length; i++) {
				lTbv_provincias[i].setTbv_regionre_id_region(null);
			}
			return delete(tbv_region);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_region tbv_region, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Tbv_provincia[] lTbv_provincias = tbv_region.tbv_provincia.toArray();
			for(int i = 0; i < lTbv_provincias.length; i++) {
				lTbv_provincias[i].setTbv_regionre_id_region(null);
			}
			try {
				session.delete(tbv_region);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_region tbv_region) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_region);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_region tbv_region) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_region);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_region loadTbv_regionByCriteria(Tbv_regionCriteria tbv_regionCriteria) {
		Tbv_region[] tbv_regions = listTbv_regionByCriteria(tbv_regionCriteria);
		if(tbv_regions == null || tbv_regions.length == 0) {
			return null;
		}
		return tbv_regions[0];
	}
	
	public Tbv_region[] listTbv_regionByCriteria(Tbv_regionCriteria tbv_regionCriteria) {
		return tbv_regionCriteria.listTbv_region();
	}
}
